

<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  
  <title>Any Component &mdash; MNMLSTC Core 1.1 documentation</title>
  

  
  

  
  <link href='https://fonts.googleapis.com/css?family=Lato:400,700|Roboto+Slab:400,700|Inconsolata:400,700' rel='stylesheet' type='text/css'>

  
  
    

  

  
  
    <link rel="stylesheet" href="_static/css/theme.css" type="text/css" />
  

  
    <link rel="top" title="MNMLSTC Core 1.1 documentation" href="index.html"/>
        <link rel="prev" title="Range Component" href="range.html"/> 

  
  <script src="https://cdnjs.cloudflare.com/ajax/libs/modernizr/2.6.2/modernizr.min.js"></script>

</head>

<body class="wy-body-for-nav" role="document">

  <div class="wy-grid-for-nav">

    
    <nav data-toggle="wy-nav-shift" class="wy-nav-side">
      <div class="wy-side-nav-search">
        <a href="index.html" class="fa fa-home"> MNMLSTC Core</a>
        <div role="search">
  <form id ="rtd-search-form" class="wy-form" action="search.html" method="get">
    <input type="text" name="q" placeholder="Search docs" />
    <input type="hidden" name="check_keywords" value="yes" />
    <input type="hidden" name="area" value="default" />
  </form>
</div>
      </div>

      <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
        
        
            <ul class="current">
<li class="toctree-l1"><a class="reference internal" href="usage.html">Using MNMLSTC Core</a><ul>
<li class="toctree-l2"><a class="reference internal" href="usage.html#library-layout">Library Layout</a></li>
<li class="toctree-l2"><a class="reference internal" href="usage.html#feature-addition-and-deprecation">Feature Addition and Deprecation</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="type-traits.html">Type Traits</a></li>
<li class="toctree-l1"><a class="reference internal" href="functional.html">Functional Utilities</a></li>
<li class="toctree-l1"><a class="reference internal" href="algorithm.html">Algorithms</a><ul>
<li class="toctree-l2"><a class="reference internal" href="algorithm.html#non-modifying-sequence-operations">Non-Modifying Sequence Operations</a></li>
<li class="toctree-l2"><a class="reference internal" href="algorithm.html#modifying-sequence-operations">Modifying Sequence Operations</a></li>
<li class="toctree-l2"><a class="reference internal" href="algorithm.html#partitioning-operations">Partitioning Operations</a></li>
<li class="toctree-l2"><a class="reference internal" href="algorithm.html#sorting-operations">Sorting Operations</a></li>
<li class="toctree-l2"><a class="reference internal" href="algorithm.html#binary-search-operations">Binary Search Operations</a></li>
<li class="toctree-l2"><a class="reference internal" href="algorithm.html#set-operations">Set Operations</a></li>
<li class="toctree-l2"><a class="reference internal" href="algorithm.html#heap-operations">Heap Operations</a></li>
<li class="toctree-l2"><a class="reference internal" href="algorithm.html#min-max-operations">Min/Max Operations</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="iterator.html">Iterator Utilities</a></li>
<li class="toctree-l1"><a class="reference internal" href="optional.html">Optional Types</a><ul>
<li class="toctree-l2"><a class="reference internal" href="optional.html#optional-type">Optional Type</a></li>
<li class="toctree-l2"><a class="reference internal" href="optional.html#expected-type">Expected Type</a></li>
<li class="toctree-l2"><a class="reference internal" href="optional.html#result-type">Result Type</a></li>
<li class="toctree-l2"><a class="reference internal" href="optional.html#functions">Functions</a></li>
<li class="toctree-l2"><a class="reference internal" href="optional.html#specializations">Specializations</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="numeric.html">Numeric Algorithms</a></li>
<li class="toctree-l1"><a class="reference internal" href="variant.html">Variant Type</a><ul>
<li class="toctree-l2"><a class="reference internal" href="variant.html#specializations">Specializations</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="utility.html">Uncategorized Utilities</a></li>
<li class="toctree-l1"><a class="reference internal" href="memory.html">Memory</a><ul>
<li class="toctree-l2"><a class="reference internal" href="memory.html#polymorphic-smart-pointer">Polymorphic Smart Pointer</a></li>
<li class="toctree-l2"><a class="reference internal" href="memory.html#deep-copying-smart-pointer">Deep Copying Smart Pointer</a></li>
<li class="toctree-l2"><a class="reference internal" href="memory.html#dumbest-smart-pointer">Dumbest Smart Pointer</a></li>
<li class="toctree-l2"><a class="reference internal" href="memory.html#utilities">Utilities</a></li>
<li class="toctree-l2"><a class="reference internal" href="memory.html#comparison-operators">Comparison Operators</a></li>
<li class="toctree-l2"><a class="reference internal" href="memory.html#make-functions">Make Functions</a></li>
<li class="toctree-l2"><a class="reference internal" href="memory.html#specializations">Specializations</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="string.html">String Utilities</a><ul>
<li class="toctree-l2"><a class="reference internal" href="string.html#specializations">Specializations</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="range.html">Range Type</a><ul>
<li class="toctree-l2"><a class="reference internal" href="range.html#specialization">Specialization</a></li>
<li class="toctree-l2"><a class="reference internal" href="range.html#answers-to-open-questions">Answers to Open Questions</a></li>
</ul>
</li>
<li class="toctree-l1 current"><a class="current reference internal" href="">Any Type</a></li>
</ul>

        
      </div>
      &nbsp;
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">

      
      <nav class="wy-nav-top" role="navigation" aria-label="top navigation">
        <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
        <a href="index.html">MNMLSTC Core</a>
      </nav>


      
      <div class="wy-nav-content">
        <div class="rst-content">
          <div role="navigation" aria-label="breadcrumbs navigation">
  <ul class="wy-breadcrumbs">
    <li><a href="index.html">Docs</a> &raquo;</li>
      
    <li>Any Component</li>
      <li class="wy-breadcrumbs-aside">
        
          <a href="_sources/any.txt" rel="nofollow"> View page source</a>
        
      </li>
  </ul>
  <hr/>
</div>
          <div role="main">
            
  <div class="section" id="any-component">
<span id="core-any-component"></span><h1>Any Component<a class="headerlink" href="#any-component" title="Permalink to this headline">¶</a></h1>
<p>The <a class="reference internal" href="#any" title="any"><tt class="xref cpp cpp-class docutils literal"><span class="pre">any</span></tt></a> component is currently available in Boost (and has been for
quite some time). There is, at the time of this writing, a <a class="reference external" href="http://beman.github.io/dot16/any-proposal.html">draft proposal</a> for a standard any type,
which has several API distinctions from the Boost.Any implementation, from which
it is inspired. Instance, the proposal recommends that an any implementation
make a small object optimization to avoid allocations for small and integral
types. The MNMLSTC Core any implements this optimization, and attempts to
follow the proposal as closely as possible.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p>The <a class="reference internal" href="#any" title="any"><tt class="xref cpp cpp-class docutils literal"><span class="pre">any</span></tt></a> component does <em>not</em> implement the
<em>allocator.uses.construction</em> constructors defined in the any proposal. The
reason for this is due to:</p>
<blockquote>
<div><ul class="simple">
<li>Several libraries do not include the constructors necessary for types
that define them</li>
<li>In most cases the compiler cannot properly disambiguate which constructor
to use, even with the use of type traits. This was mentioned on the LLVM
blog, and is mentioned as part of
<a class="reference external" href="http://cplusplus.github.io/LWG/lwg-active.html#2255">LWG Defect 2255</a>.</li>
</ul>
</div></blockquote>
<p class="last">Because this component was written for C++11, it was decided to omit these
additional allocator aware constructors.</p>
</div>
<dl class="class">
<dt id="bad_any_cast">
<em class="property">class </em><tt class="descname">bad_any_cast</tt><a class="headerlink" href="#bad_any_cast" title="Permalink to this definition">¶</a></dt>
<dd><table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Inherits:</th><td class="field-body">std::bad_cast</td>
</tr>
</tbody>
</table>
<p>This is the exception thrown when <a class="reference internal" href="#any_cast__anyCR" title="any_cast"><tt class="xref cpp cpp-func docutils literal"><span class="pre">any_cast()</span></tt></a> fails.
It inherits from <tt class="docutils literal"><span class="pre">std::bad_cast</span></tt>.</p>
<dl class="function">
<dt id="bad_any_cast::whatC">
char const* <tt class="descname">what</tt><big>(</big><big>)</big><tt class="descclassname"> const</tt><tt class="descclassname"> noexcept</tt><a class="headerlink" href="#bad_any_cast::whatC" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns the string &#8220;bad any cast&#8221;. At some point in the future a more
descriptive error may be given.</p>
</dd></dl>

</dd></dl>

<dl class="class">
<dt id="any">
<em class="property">class </em><tt class="descname">any</tt><a class="headerlink" href="#any" title="Permalink to this definition">¶</a></dt>
<dd><dl class="function">
<dt id="any::any__X">
 <tt class="descname">any</tt><big>(</big><em>any const&amp;</em><big>)</big><a class="headerlink" href="#any::any__X" title="Permalink to this definition">¶</a></dt>
<dt>
 <tt class="descname">any</tt><big>(</big><em>any&amp;&amp;</em><big>)</big><tt class="descclassname"> noexcept</tt></dt>
<dt id="any::any">
 <tt class="descname">any</tt><big>(</big><big>)</big><tt class="descclassname"> noexcept</tt><a class="headerlink" href="#any::any" title="Permalink to this definition">¶</a></dt>
<dd><p>The default set of constructors work as one might imagine. The copy
constructor is not marked as noexcept as the underlying type <em>may</em>
throw an exception, and due to the type erasure performed, the <a class="reference internal" href="#any" title="any"><tt class="xref cpp cpp-class docutils literal"><span class="pre">any</span></tt></a> has
no way of enforcing this at compile time.</p>
</dd></dl>

<dl class="function">
<dt id="any::any__ValueTypeRR">
 <tt class="descname">any</tt><big>(</big>ValueType&amp;&amp; <em>value</em><big>)</big><a class="headerlink" href="#any::any__ValueTypeRR" title="Permalink to this definition">¶</a></dt>
<dd><p>When constructing an <a class="reference internal" href="#any" title="any"><tt class="xref cpp cpp-class docutils literal"><span class="pre">any</span></tt></a> with a given <tt class="docutils literal"><span class="pre">ValueType</span></tt>, it will perform a
series of compile time checks to see whether it should perform the small
object optimization. If the object is deemed small enough, it will not
allocate memory. Otherwise, a new ValueType will be allocated via
operator new, and constructed with the given <em>value</em>.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Type value:</th><td class="field-body">ValueType&amp;&amp;</td>
</tr>
<tr class="field-even field"><th class="field-name">Raises:</th><td class="field-body">Any exceptions thrown by the copy or move constructor
of the given ValueType.</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="function">
<dt id="any::assign-operator__X">
any&amp; <tt class="descname">operator=</tt><big>(</big><em>any const&amp;</em><big>)</big><a class="headerlink" href="#any::assign-operator__X" title="Permalink to this definition">¶</a></dt>
<dt>
any&amp; <tt class="descname">operator=</tt><big>(</big><em>any&amp;&amp;</em><big>)</big><tt class="descclassname"> noexcept</tt></dt>
<dd><p>Assigns the contents of the incoming <a class="reference internal" href="#any" title="any"><tt class="xref cpp cpp-class docutils literal"><span class="pre">any</span></tt></a> to <tt class="docutils literal"><span class="pre">*this</span></tt>.</p>
</dd></dl>

<dl class="function">
<dt id="any::assign-operator__ValueTypeRR">
any&amp; <tt class="descname">operator=</tt><big>(</big>ValueType&amp;&amp; <em>value</em><big>)</big><a class="headerlink" href="#any::assign-operator__ValueTypeRR" title="Permalink to this definition">¶</a></dt>
<dd><p>Assigns <em>value</em> to <tt class="docutils literal"><span class="pre">*this</span></tt>. If <tt class="docutils literal"><span class="pre">*this</span></tt> already manages a contained
object, it will be destroyed after <em>value</em> is assigned.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 1.1: </span>This function was unfortunately omitted from the 1.0 release.</p>
</div>
</dd></dl>

<dl class="function">
<dt id="any::any::swap__X">
void <tt class="descclassname">any::</tt><tt class="descname">swap</tt><big>(</big><em>any&amp;</em><big>)</big><tt class="descclassname"> noexcept</tt><a class="headerlink" href="#any::any::swap__X" title="Permalink to this definition">¶</a></dt>
<dd><p>Swaps the object contained within the given <a class="reference internal" href="#any" title="any"><tt class="xref cpp cpp-class docutils literal"><span class="pre">any</span></tt></a> with the one contained
within <tt class="docutils literal"><span class="pre">*this</span></tt>.</p>
</dd></dl>

<dl class="function">
<dt id="any::typeC">
std::type_info const&amp; <tt class="descname">type</tt><big>(</big><big>)</big><tt class="descclassname"> const</tt><tt class="descclassname"> noexcept</tt><a class="headerlink" href="#any::typeC" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns the <tt class="docutils literal"><span class="pre">std::type_info</span></tt> for the type contained within. If the
<a class="reference internal" href="#any" title="any"><tt class="xref cpp cpp-class docutils literal"><span class="pre">any</span></tt></a> is empty, it will return <tt class="docutils literal"><span class="pre">typeid(void)</span></tt>.</p>
</dd></dl>

<dl class="function">
<dt id="any::emptyC">
bool <tt class="descname">empty</tt><big>(</big><big>)</big><tt class="descclassname"> const</tt><tt class="descclassname"> noexcept</tt><a class="headerlink" href="#any::emptyC" title="Permalink to this definition">¶</a></dt>
<dd><p>If the <a class="reference internal" href="#any" title="any"><tt class="xref cpp cpp-class docutils literal"><span class="pre">any</span></tt></a> does not contain any data (i.e. <a class="reference internal" href="#any::typeC" title="any::type"><tt class="xref cpp cpp-func docutils literal"><span class="pre">any::type()</span></tt></a> returns
<tt class="docutils literal"><span class="pre">typeid(void)</span></tt>), it will return true.</p>
</dd></dl>

<dl class="function">
<dt id="any::clear">
void <tt class="descname">clear</tt><big>(</big><big>)</big><tt class="descclassname"> noexcept</tt><a class="headerlink" href="#any::clear" title="Permalink to this definition">¶</a></dt>
<dd><table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Postcondition:</th><td class="field-body"><a class="reference internal" href="#any::emptyC" title="any::empty"><tt class="xref cpp cpp-func docutils literal"><span class="pre">any::empty()</span></tt></a> == true</td>
</tr>
</tbody>
</table>
<p>Destroys the object contained within the <a class="reference internal" href="#any" title="any"><tt class="xref cpp cpp-class docutils literal"><span class="pre">any</span></tt></a>.</p>
</dd></dl>

</dd></dl>

<dl class="function">
<dt id="any_cast__anyCR">
ValueType <tt class="descname">any_cast</tt><big>(</big>any const&amp; <em>operand</em><big>)</big><a class="headerlink" href="#any_cast__anyCR" title="Permalink to this definition">¶</a></dt>
<dt id="any_cast__anyRR">
ValueType <tt class="descname">any_cast</tt><big>(</big>any&amp;&amp; <em>operand</em><big>)</big><a class="headerlink" href="#any_cast__anyRR" title="Permalink to this definition">¶</a></dt>
<dt id="any_cast__anyR">
ValueType <tt class="descname">any_cast</tt><big>(</big>any&amp; <em>operand</em><big>)</big><a class="headerlink" href="#any_cast__anyR" title="Permalink to this definition">¶</a></dt>
<dd><table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body"><tt class="docutils literal"><span class="pre">*any_cast&lt;add_const_t&lt;remove_reference_t&lt;ValueType&gt;&gt;(&amp;operand)</span></tt>
for the first <a class="reference internal" href="#any_cast__anyCR" title="any_cast"><tt class="xref cpp cpp-func docutils literal"><span class="pre">any_cast()</span></tt></a> signature. For the other overloads,
the return type is
<tt class="docutils literal"><span class="pre">*any_cast&lt;remove_reference_t&lt;ValueType&gt;&gt;(&amp;operand)</span></tt>.</td>
</tr>
<tr class="field-even field"><th class="field-name">Raises:</th><td class="field-body"><a class="reference internal" href="#bad_any_cast" title="bad_any_cast"><tt class="xref cpp cpp-class docutils literal"><span class="pre">bad_any_cast</span></tt></a></td>
</tr>
</tbody>
</table>
<p>Given a type <em>ValueType</em>, it will attempt to extract the value stored within
the given <a class="reference internal" href="#any" title="any"><tt class="xref cpp cpp-class docutils literal"><span class="pre">any</span></tt></a>. <em>ValueType</em> may be either concrete or a reference type.
If <tt class="docutils literal"><span class="pre">typeid(remove_reference_t&lt;ValueType&gt;)</span></tt> is not equal to the value
returned by <a class="reference internal" href="#any::typeC" title="any::type"><tt class="xref cpp cpp-func docutils literal"><span class="pre">any::type()</span></tt></a>, <a class="reference internal" href="#bad_any_cast" title="bad_any_cast"><tt class="xref cpp cpp-class docutils literal"><span class="pre">bad_any_cast</span></tt></a> is thrown. Some
usage examples:</p>
<div class="highlight-cpp"><div class="highlight"><pre><span class="n">any</span> <span class="nf">x</span><span class="p">(</span><span class="mi">5</span><span class="p">)</span> <span class="c1">// x holds an int</span>
<span class="k">auto</span> <span class="n">y</span> <span class="o">=</span> <span class="n">any_cast</span><span class="o">&lt;</span><span class="kt">int</span><span class="o">&gt;</span><span class="p">(</span><span class="n">x</span><span class="p">);</span> <span class="c1">// cast to a value</span>
<span class="n">any_cast</span><span class="o">&lt;</span><span class="kt">int</span><span class="o">&amp;&gt;</span><span class="p">(</span><span class="n">x</span><span class="p">)</span> <span class="o">=</span> <span class="mi">10</span><span class="p">;</span> <span class="c1">// cast to a reference for mutation.</span>

<span class="n">x</span> <span class="o">=</span> <span class="n">std</span><span class="o">::</span><span class="n">string</span> <span class="p">{</span> <span class="s">&quot;Woof&quot;</span> <span class="p">};</span> <span class="c1">// x now holds a string.</span>
<span class="k">auto</span> <span class="n">woof</span> <span class="o">=</span> <span class="n">std</span><span class="o">::</span><span class="n">move</span><span class="p">(</span><span class="n">any_cast</span><span class="o">&lt;</span><span class="n">std</span><span class="o">::</span><span class="n">string</span><span class="o">&amp;&gt;</span><span class="p">(</span><span class="n">x</span><span class="p">));</span> <span class="c1">// move value in x</span>
<span class="n">assert</span><span class="p">(</span><span class="n">any_cast</span><span class="o">&lt;</span><span class="n">std</span><span class="o">::</span><span class="n">string</span> <span class="k">const</span><span class="o">&amp;&gt;</span><span class="p">(</span><span class="n">x</span><span class="p">)</span> <span class="o">==</span> <span class="s">&quot;&quot;</span><span class="p">);</span>
</pre></div>
</div>
</dd></dl>

<dl class="function">
<dt id="any_cast__anyCP">
ValueType const* <tt class="descname">any_cast</tt><big>(</big>any const* <em>operand</em><big>)</big><a class="headerlink" href="#any_cast__anyCP" title="Permalink to this definition">¶</a></dt>
<dt id="any_cast__anyP">
ValueType* <tt class="descname">any_cast</tt><big>(</big>any* <em>operand</em><big>)</big><a class="headerlink" href="#any_cast__anyP" title="Permalink to this definition">¶</a></dt>
<dd><table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body"><em>ValueType</em> if operand is not equal to <tt class="docutils literal"><span class="pre">nullptr</span></tt> and
<tt class="docutils literal"><span class="pre">typeid(ValueType)</span></tt> is the same as the value returned by
<a class="reference internal" href="#any::typeC" title="any::type"><tt class="xref cpp cpp-func docutils literal"><span class="pre">any::type()</span></tt></a>, a pointer to the object managed by <em>operand</em>
is returned. Otherwise, <tt class="docutils literal"><span class="pre">nullptr</span></tt>.</td>
</tr>
</tbody>
</table>
</dd></dl>

</div>


          </div>
          <footer>
  
    <div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
      
      
        <a href="range.html" class="btn btn-neutral" title="Range Component"><span class="fa fa-arrow-circle-left"></span> Previous</a>
      
    </div>
  

  <hr/>

  <div role="contentinfo">
    <p>
        &copy; Copyright 2013 - 2014, MNMLSTC.
    </p>
  </div>

  <a href="https://github.com/snide/sphinx_rtd_theme">Sphinx theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>
</footer>
        </div>
      </div>

    </section>

  </div>
  


  

    <script type="text/javascript">
        var DOCUMENTATION_OPTIONS = {
            URL_ROOT:'./',
            VERSION:'1.1',
            COLLAPSE_INDEX:false,
            FILE_SUFFIX:'.html',
            HAS_SOURCE:  true
        };
    </script>
      <script type="text/javascript" src="_static/jquery.js"></script>
      <script type="text/javascript" src="_static/underscore.js"></script>
      <script type="text/javascript" src="_static/doctools.js"></script>

  

  
  
    <script type="text/javascript" src="_static/js/theme.js"></script>
  

  
  
  <script type="text/javascript">
      jQuery(function () {
          SphinxRtdTheme.StickyNav.enable();
      });
  </script>
   

</body>
</html>